package com.rh.number.common;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)  // 忽略 null 字段
public class ResponseResult<T> {
    private int code;
    private String msg;
    private T data;
    private String token;

    // 基础构造器
    public ResponseResult() {}

    // 带全参数的构造器
    public ResponseResult(int code, String msg, T data, String token) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.token = token;
    }

    // 快速构建成功响应
    public static <T> ResponseResult<T> success(T data, String token) {
        return new ResponseResult<>(200, "成功", data, token);
    }
    public void setData(T data) {
        this.data = data;
    }
    public static <T> ResponseResult<T> error(int code, String message) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(code);
        result.setMsg(message);
        return result;
    }

    public void setMsg(String msg) {  // 参数名改为英文
        this.msg = msg;
    }

    public void setCode(int code) {  // 需要 public 访问权限
        this.code = code;
    }

    public int getCode() { return code; }
    public String getMsg() { return msg; }
    public T getData() { return data; }
    public String getToken() { return token; }

}